import { http } from '@/utils/http'
import { defineStore } from 'pinia'

export const useBaseStore = defineStore(
	'base',
	() => {
		const currency = ref(null)
		const currencyList = ref([])
		const initCurrency = async () => {
			if (!language) {
				language.value = languageList.value[0]
				uni.setLocale(language.value.code)
			}

			let res: any = await http.get('/currency')
			if (res.code == 200) {
				console.log('res', res)
				currencyList.value = res.data.list

				if (!currency.value) {
					currency.value = currencyList.value[0]
				}
			}
		}

		const language = ref({ code: 'zh-Hans', name: '中文' })

		const languageList = ref([
			{ code: 'zh-Hans', name: '中文' },
			{ code: 'es', name: 'Español' },
			{ code: 'en', name: 'English' },
		])

		return { currency, currencyList, initCurrency, language, languageList }
	},
	{
		persist: true,
	},
)
